﻿#region File and License Information
/*
<File>
	<License>
		Copyright © 2009 - 2017, Daniel Vaughan. All rights reserved.
		This file is part of Calcium (http://calciumsdk.net), 
		which is released under the MIT License.
		See file /Documentation/License.txt for details.
	</License>
	<CreationDate>2011-02-20 17:28:38Z</CreationDate>
</File>
*/
#endregion

using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace Outcoder.Services.Implementation
{
	[TemplatePart(Name = OKButtonName, Type = typeof(ButtonBase))]
	[TemplatePart(Name = CancelButtonName, Type = typeof(ButtonBase))]
	public class TextResponseWindow : ChildWindow
	{
		const string OKButtonName = "OKButton";
		const string CancelButtonName = "CancelButton";

		public TextResponseWindow()
		{
			DefaultStyleKey = typeof(TextResponseWindow);
			DataContext = this;
		}

		public string Response { get; set; }
		public string Caption { get; set; }

		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();

			var okButton = (ButtonBase)GetTemplateChild(OKButtonName);
			if (okButton != null)
			{
				okButton.Click += (sender, eventArgs) =>
				{
					DialogResult = true;
					Close();
				};
			}

			var cancelButton = (ButtonBase)GetTemplateChild(CancelButtonName);

			if (cancelButton != null)
			{
				cancelButton.Click += (sender, eventArgs) =>
				{
					DialogResult = false;
					Close();
				};
			}
		}
	}
}
